package com.hyg.common.utils;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Author: huangyuguang
 * Date: 2022/5/5
 */
public class CustomThreadPool extends ThreadPoolExecutor {
    public String Tag = "";
    public CustomThreadPool(String tag,
                            int corePoolSize,
                            int maximumPoolSize,
                            long keepAliveTime,
                            TimeUnit unit,
                            BlockingQueue<Runnable> workQueue,
                            ThreadFactory threadFactory) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
        Tag = tag;
    }

    public CustomThreadPool(String tag,
                            int corePoolSize,
                            int maximumPoolSize,
                            long keepAliveTime,
                            TimeUnit unit,
                            BlockingQueue<Runnable> workQueue,
                            ThreadFactory threadFactory,
                            RejectedExecutionHandler rejectedExecutionHandler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory,rejectedExecutionHandler );
        Tag = tag;
    }
    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        super.beforeExecute(t, r);
       //LogUtils.d(Tag+"beforeExecute: 开始执行任务！");
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        //LogUtils.d( Tag+"afterExecute: 任务执行结束！");
    }

    @Override
    protected void terminated() {
        super.terminated();
        //当调用shutDown()或者shutDownNow()时会触发该方法
//        LogUtils.d(Tag+"terminated: 线程池关闭！");
    }

}
